package com.atguigu.edu.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @ClassName RedisUtil
 * @Description TODO 操作Redis的工具类
 * @Author AFei
 * @Date 2022/9/4 10:52
 * @Version 1.0
 */
public class RedisUtil {
    private static JedisPool jedisPool;
    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(100);
        jedisPoolConfig.setMaxIdle(5);
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(2000);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisPool = new JedisPool(jedisPoolConfig,"hadoop101",6379,10000);
    }
     private static Jedis getJedis(){
         System.out.println("~~~初始化Jedis客户端~~~");
         Jedis jedis = jedisPool.getResource();
         return jedis;
     }
     private static void main(String[] args) {
         Jedis jedis = getJedis();
         String pong = jedis.ping();
         System.out.println(pong);
     }
}
